# 基本数据结构的CRUD操作基本数据结构的CRUD操作

# List(列表)
my_list = ['abc', 'efg', 'b']

# 增加(Create)
x = my_list * 2
print(x)
x = my_list + ["c", 'ggg']
print(x)

# append(添加)
my_list.append('ABC')
print(my_list)
# insert 指定位置插入元素
my_list.insert(1, '123')
print(my_list)

# 检索(Retrieve)
a = my_list[1:]
b = my_list[:4]
c = my_list[-1]
d = my_list.index('ABC')
e = my_list.insert(d, 'hhhh')
print(a, b, c, d, my_list)

# 更新(Update)
my_list[2] = 'xxx'
print(my_list)
my_list[2:3] = "x"
print(my_list)

# 更新(Update)
my_list.pop()
print(my_list)
my_list.remove('abc')
print(my_list)

# *统计和排序
my_list2 = ['a', 'a', 'b', 'abb']
print(my_list2.count('a'))
my_list2.reverse()
print(my_list2)
b = reversed(my_list2)
print(list(b))

li = [1, 2, 3, 4, 5, 1]
li.sort()
print(li)
li.sort(reverse=True)
print(li)
print(sorted(li))

# tuple
my_tuple = (2, 4, 5, 6)
print(my_tuple.index(4))
print(my_tuple[3])

# dict
my_dict = {"a": 12, "b": 13}
my_dict_2 = {"c": 23, "d": 23}
d_3 = my_dict.update(my_dict_2)
print(my_dict)
my_dict.setdefault('e', 1)
print(my_dict)
my_dict.setdefault('d', 1)
print(my_dict)
# 检索(Retrieve)
print(my_dict['a'])
print(my_dict.get('g', "没找到"))
print(my_dict.get('a', "没找到"))
print(my_dict.keys())
print(my_dict.values())
print(my_dict.items())
my_dict.update({"a": 1})
print(my_dict)
my_dict.pop('a')
print(my_dict)
my_dict.clear()
print(my_dict)

# set
my_set = {1, 'ss', 'sssd', 4, 9}
my_set.add("3")
print(my_set)
if 4 in my_set:
    print("找到了4!")
my_set2 = {2, '12', '33', 5, 8}
my_set.update(my_set2)
print(my_set)
print(my_set.union({'2', '444'}))
my_set.remove('ss')
print(my_set)
my_set.discard('12')
print(my_set)
my_set.pop()
print(my_set)